<!DOCTYPE html>
<html>
<include file="Public:header" />
<link href="__ACSS__/dialog.css" rel="stylesheet">
<link href="__ACSS__/plugins/validform/validform.css" rel="stylesheet">
<link href="__ACSS__/plugins/clockpicker/clockpicker.css" rel="stylesheet">
<style>
	.form-control{ padding-left:5px;}
	.upload-warp{ position:relative;}
	.upload-btn{ position:absolute; top:0; right:0; border-radius:0;}
	
	.file-preview { border:1px solid #ddd; padding:5px; width:100%; margin-bottom:5px;}
	.file-preview-frame{ margin:8px; border:1px solid #ddd; box-shadow:1px 1px 5px 0px #a2958a; padding:6px; float:left; text-align:center; vertical-align:middle;}
	.file-preview-frame .btn{ float:right; margin-top:5px;}
	.file-preview-text{ color:#428bca; font-size:11px; text-align:center;}
	#tipinput{ position:absolute; top:0; z-index:999999; width:50%; margin-left:25%; margin-top:10px; box-shadow:0 5px 15px 0 rgba(0, 0, 0, 0.4);}
	.clockpicker{ width:46%; float:left;}
	.clockpicker-addon{ width:8%; height:34px; line-height:34px; text-align:center; float:left;}
</style>
  <body>
	  <div class="wrapper wrapper-content animated fadeInRight">
	  	<div role="alert" class="alert alert-info" style="line-height:24px;"><strong>可以添加多个时间段，避免时间段冲突！</strong></div>
	  	<form role="form" class="form" action="__URL__/insert">
			<input type="hidden" name="flag" value="1">
			<input type="hidden" name="create_time" value="<php>echo time();</php>">
			<div class="form-group">
				<label class="col-sm-2 control-label">配送时间：</label>
				<div class="col-sm-10">
					<div class="input-group clockpicker" data-placement="bottom" data-align="top" data-autoclose="true">
					    <input type="text" class="form-control opening-input" id="opening_begin" readonly="readonly" name="begin_time">
					    <span class="input-group-addon">
					        <span class="glyphicon glyphicon-time"></span>
					    </span>
					</div>
					<span class="clockpicker-addon">至</span>				
					<div class="input-group clockpicker" data-placement="bottom" data-align="top" data-autoclose="true">
					    <input type="text" class="form-control opening-input" id="opening_end" readonly="readonly" name="end_time">
					    <span class="input-group-addon">
					        <span class="glyphicon glyphicon-time"></span>
					    </span>
					</div>
					<span class="Validform_checktip"></span>
				</div>
			</div>
			<div class="clearfix">
				<button type="submit" id="submit" class="btn btn-success btn-block">提交</button>
				<button type="reset" id="reset2" class="btn btn-success btn-block hidden">重置</button>
			</div>
		</form>
	  </div>
  </body>
<!-- 全局js -->
<include file="Public:foot" />
<script src="__AJSPLUGINS__/validform/Validform_v5.3.2_min.js"></script>
<!-- Clock picker -->
<script src="__AJSPLUGINS__/clockpicker/clockpicker.js"></script>
<script>
$(function(){
	$('.clockpicker').clockpicker();
	$("#reset2").click();
	var index = parent.layer.getFrameIndex(window.name);
	var form = $(".form").Validform({
		tiptype:4,
		ajaxPost:true,
		beforeSubmit:function(curform){
			if(!verify()) {
				return false;
			}
		},
		callback:function(data){
			if(data.status == 1) {
				window.parent.layer.msg(data.info);
				window.parent.$('#table_list').trigger("reloadGrid");
			}else{
				window.parent.layer.msg(data.info);
			}
			parent.layer.close(index);
		}
	});
	
	function verify(){
		var opening_begin = $("#opening_begin");
		var opening_end = $("#opening_end");
		if(opening_begin.val() == "" || opening_end.val() == "") {
			$(".clockpicker").parents(".col-sm-10").find(".Validform_checktip").show();
			$(".clockpicker").parents(".col-sm-10").find(".Validform_checktip").attr("class","Validform_checktip Validform_wrong");
			$(".clockpicker").parents(".col-sm-10").find(".Validform_checktip").html("请选择时间");
			return false;
		}else{
			if(compare(opening_begin.val(),opening_end.val()) == false){
				$(".clockpicker").parents(".col-sm-10").find(".Validform_checktip").show();
				$(".clockpicker").parents(".col-sm-10").find(".Validform_checktip").attr("class","Validform_checktip Validform_wrong");
				$(".clockpicker").parents(".col-sm-10").find(".Validform_checktip").html("开始时间不能大于结束时间");
				return false;
			}else{
				$(".clockpicker").parents(".col-sm-10").find(".Validform_checktip").show();
				$(".clockpicker").parents(".col-sm-10").find(".Validform_checktip").attr("class","Validform_checktip Validform_right");
				$(".clockpicker").parents(".col-sm-10").find(".Validform_checktip").html("通过信息验证！");
				return true;
			}
		}
	}
	//比对时间大小
	function compare(a, b) {
	    var arr = a.split(":");
	    var starttime = new Date("1970", "1", "1", arr[0], arr[1]);
	    var starttimes = starttime.getTime();
	    var arrs = b.split(":");
	    var lktime = new Date("1970", "1", "1", arrs[0], arrs[1]);
	    var lktimes = lktime.getTime();
	    if (starttimes > lktimes) {
	        return false;
	    }
	    else
	        return true;
	}
})
</script>
</html>